package qlsl.androiddesign.http.service.subservice;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import qlsl.androiddesign.constant.WhatConstant;
import qlsl.androiddesign.entity.otherentity.ThreeCategory;
import qlsl.androiddesign.handler.subhandler.HttpHandler;
import qlsl.androiddesign.http.HttpListener;
import qlsl.androiddesign.http.service.baseservice.BaseService;
import qlsl.androiddesign.http.xutils.HttpProtocol;
import qlsl.androiddesign.thread.HandlerThread;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 三级分类模块 <br/>
 * 
 */
public class CategoryService extends BaseService {

	private static String className = getClassName(CategoryService.class);

	public static void queryCatagoryList(final int subtierid, final FunctionView<?> functionView,
			final HttpListener listener) {
		final HttpHandler handler = getHandler(functionView, listener, className, "queryCatagoryList");
		new HandlerThread(className, "queryCatagoryList") {
			public void run() {
				HttpProtocol protocol = new HttpProtocol();
				try {
					JSONObject jo = protocol.setMethod("getsumciergoodstypelist").addParam("subtierid", subtierid)
							.post();

					if (isDataInvalid(jo, handler, protocol)) {
						return;
					}

					// Object object = JSON.toJavaObject(jo, Object.class);
					List<ThreeCategory.RowsBean> list = JSONArray.parseArray(jo.getString("rows"),
							ThreeCategory.RowsBean.class);
					handler.sendMessage(protocol, WhatConstant.WHAT_NET_DATA_SUCCESS, list);
				} catch (Exception e) {
					e.printStackTrace();
					handler.sendMessage(protocol, WhatConstant.WHAT_EXCEPITON, e);
				}
			};
		}.start();
	}
}
